class Solution {
    public int numIslands(char[][] grid) {
        int hang=grid.length;
        int lie=grid[0].length;
        int island=0;
        for(int x=0;x<hang;x++)
        {
            for(int y=0;y<lie;y++)
            {
                if(grid[x][y]=='1')
                {
                    island++;
                    dfs(grid,x,y);
                }
            }
        }
        return island;
    }
    public void dfs(char[][]grid,int x,int y)
    {
        int hang=grid.length;
        int lie=grid[0].length;
        if(x<0||y<0||x>=hang||y>=lie||grid[x][y]=='0')
        return;
        grid[x][y]='0';
        dfs(grid,x+1,y);
        dfs(grid,x,y+1);
        dfs(grid,x-1,y);
        dfs(grid,x,y-1);
    }
}
